/*
 * Copyright (c) 2013, marco.tamburelli@gmail.com
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met: 
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.omorphdb.core.value;

/**
 * A wrapper of a value.<br>
 * <br>
 * 
 * Objects implementing this interface are just transparent wrappers to values
 * read from/wrote to the storage.
 * 
 * @param <T>
 */
public interface Value<T>
{
	/**
	 * Returns a value from {@link ValueType} defining the type of wrapped
	 * element.
	 * 
	 * @return
	 */
	ValueType getType();

	/**
	 * Tries to obtain the java type of the value. For primitive type is
	 * obvious. This method in case of array, attempts to retrieve the type of
	 * the expected array. Note that in case the inner array is not homogeneous
	 * the type could not be determined correctly.
	 * 
	 * 
	 * In case of {@link ObjectValue} it will return the document type.
	 * 
	 * @return
	 */
	Class<?> getJavaType();

	/**
	 * Returns the element wrapped by the value.
	 * 
	 * @return
	 */
	T get();

	/**
	 * Returns the size in bytes of the wrapped element.
	 * 
	 * @return
	 */
	int size();

	/**
	 * Returns true when the wrapped values is undefined or is null.
	 * 
	 * @return
	 */
	boolean isNull();
}
